﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows;

namespace VisualTest2
{
    class VisualUtilities
    {
        public static Path CreatePolygonPath(PointCollection collection, bool isAntialised)
        {            
            Path myPath = new Path();
            myPath.IsHitTestVisible = false;
            if (isAntialised)
            {
                myPath.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
            }
            myPath.Stroke = Brushes.Black;
            myPath.StrokeThickness = 1.0;
            myPath.StrokeLineJoin = PenLineJoin.Round;
            StreamGeometry geometry = new StreamGeometry();
            geometry.FillRule = FillRule.EvenOdd;
            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(collection[0].X, collection[collection.Count - 1].Y),
                    false /* is filled */, false /* is closed */);
                ctx.PolyLineTo(collection, true, false);
            }
            geometry.Freeze();
            myPath.Data = geometry;
            return myPath;
        }

        public static void addLineGeometries(PointCollection collection,GeometryGroup gr)
        {            
                        
            for (int i = 0; i < collection.Count - 1; i++)
            {
                // Create new line geometry                
                LineGeometry line = new LineGeometry();
                line.StartPoint = new Point(collection[i].X, collection[i].Y);
                line.EndPoint = new Point(collection[i + 1].X, collection[i + 1].Y);
                // return line for further processing
                gr.Children.Add(line);
                line.Freeze();
            }
        }

    
    }
}
